package com.springcloud.web;


import com.springcloud.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
public class RestTestController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/restTest01")
    public String restTest01(){
        String url="http://eureka-client-provider/providerRestTest01";
        ResponseEntity<String> result = restTemplate.getForEntity(url, String.class);
        String body = result.getBody();
        return body;

    }
    @GetMapping("/restTest02")
    public User restTest02(){
        String url="http://eureka-client-provider/providerRestTest02?userId={userId}";

        Map<String,Object> params=new HashMap<>();
        params.put("userId",02);
        User result = restTemplate.getForObject(url, User.class,params);
        return result;
    }


}
